faApp.controller('SimuCompanyListCtrl',['$scope','simuCompanyService','$location','$controller','$route',function($scope,simuCompanyService,$location,$controller,$route) {   
	$controller('BaseCtrl', {$scope: $scope}); 

  $scope.list = [];
  $scope.loading = true;

	$scope.$watch('config',function(){
    simuCompanyService.list($scope.config).then(function(json){
      $scope.list = json.list;
      $scope.pager = json.pager;
      $scope.loading = false;
    });
  },true)

	$scope.config = {
		"pageSize" : 20,
		"pageNo" : 1
	};

  $scope.searchMap = {
		"gsmc" : '', 
  };

  $scope.search = function(){

    angular.forEach($scope.searchMap,function(o,i){
      $scope.config[i] = ( undefined == $scope.searchMap[i] ? "" : $scope.searchMap[i]);
    });

  };
  
  
	$scope.pageChanged = function(){
		$scope.config.pageNo = $scope.pager.pageNo;
	}; 
  
  
  $scope.remove = function(id){
    simuCompanyService.remove({id:id}).then(function(json){
      if (json.statusCode){
        alert("出错了:" + json.statusCode);
      }else{
        $route.reload();
      }
    });
  };
}]);

faApp.controller('SimuCompanyAddCtrl',['$scope','simuCompanyService','simuService','$location','$controller','$route',function($scope,simuCompanyService,simuService,$location,$controller,$route) {   
	$controller('BaseCtrl', {$scope: $scope}); 

  $scope.item = {}; 
   $scope.getJJBM=function(){
    simuService.queryjjbm({"type":"GS","digit":"5"}).then(function(json){
       $scope.item.jjgsbm=json.code;
    });
  };
  $scope.getJJBM();
  $scope.save = function(){
    if ($scope.form.$invalid){
      alert("请先正确填写表单");
      return;
    }else{
      if ($scope.item.clrqstr)$scope.item.clrq = $scope.item.clrqstr + " 00:00:00";
      simuCompanyService.add($scope.item).then(function(json){
        if (json.statusCode){
          if(json.statusCode=='2003'){
            alert("公司编码重复");
          }else{
           alert("出错了:" + json.statusCode);
          }
        }else{
          $location.path("/simu/company/list");
        }
      });
    }
  };
  
}]);

faApp.controller('SimuCompanyEditCtrl',['$scope','simuCompanyService','$location','$controller','$route','$routeParams','$filter',function($scope,simuCompanyService,$location,$controller,$route,$routeParams,$filter) {   
	$controller('BaseCtrl', {$scope: $scope}); 

  $scope.item = {};
  $scope.loading = true;
  $scope.id = $routeParams.id;

  simuCompanyService.query({id:$scope.id}).then(function(json){
    $scope.item = json.detail;
    $scope.item.clrqstr = $filter("date")($scope.item.clrq,"yyyy-MM-dd");
    delete $scope.item.clrq;
    $scope.loading = false;
  });
  
  $scope.save = function(){
    if ($scope.form.$invalid){
      alert("请先正确填写表单");
      return;
    }else{
      if ($scope.item.clrqstr)$scope.item.clrq = $scope.item.clrqstr + " 00:00:00";
      simuCompanyService.edit($scope.item).then(function(json){
        if (json.statusCode){
          alert("出错了:" + json.statusCode);
        }else{
          $location.path("/simu/company/list");
        }
      });
    }
  };
}]);

faApp.controller('SimuCompanyViewCtrl',['$scope','$sce','simuCompanyService','$location','$controller','$route','$routeParams',function($scope,$sce,simuCompanyService,$location,$controller,$route,$routeParams) {   
	$controller('BaseCtrl', {$scope: $scope}); 

  $scope.item = [];
  $scope.loading = true;
  $scope.id = $routeParams.id;
  
  simuCompanyService.query({id:$scope.id}).then(function(json){
    $scope.item = json.detail;
    //前台html展示
    $scope.item.tdjj=$sce.trustAsHtml($scope.item.tdjj);
    $scope.item.investIdea=$sce.trustAsHtml($scope.item.investIdea);
    $scope.item.investTeam=$sce.trustAsHtml($scope.item.investTeam);

  });

	$scope.config = {
		"pageSize" : 20,
		"pageNo" : 1
	};
  
	$scope.pageChanged = function(){
		$scope.config.pageNo = $scope.pager.pageNo;
	}; 
  
  $scope.remove = function(id){
    simuCompanyService.remove({id:id}).then(function(json){
      if (json.statusCode){
        alert("出错了:" + json.statusCode);
      }else{
        $location.path("/simu/company/list");
      }
    });
  };
}]);





